﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Shpm.App.Input.Dao;
using Shpm.App.Input.Bean;
using Shpm.App.Commons.Utils;

public partial class App_Input_EeployeeDinnerSrhForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        txtEmpId.Attributes.Add("onblur", "showEmployeeName(this.id,'" + txtEmpName.ClientID + "');");
        txtEmpName.Attributes.Add("onfocus", "document.getElementById('" + txtEmpId.ClientID + "').focus();");
        if (!IsPostBack)
        {
            this.ViewState["EMPLOYEE_ID"]=null;
            this.ViewState["DINNER_DATE"] = null;
            this.ViewState["EMPLOYEE_NAME"] = null;
            if (Context.Items["EMPLOYEE_ID"] != null)
            {
                ViewState["EMPLOYEE_ID"] = Context.Items["EMPLOYEE_ID"];
                txtEmpId.Text = Convert.ToString(ViewState["EMPLOYEE_ID"]);
            }
            if (Context.Items["DINNER_DATE"] != null)
            {
                ViewState["DINNER_DATE"] = Context.Items["DINNER_DATE"];
                txtDate.Text = Convert.ToString(ViewState["DINNER_DATE"]);
            }
            if (Context.Items["EMPLOYEE_NAME"] != null)
            {
                ViewState["EMPLOYEE_NAME"] = Context.Items["EMPLOYEE_NAME"];
                txtEmpName.Text = Convert.ToString(ViewState["EMPLOYEE_NAME"]);
            }

            if (ViewState["EMPLOYEE_NAME"] != null || ViewState["DINNER_DATE"] != null || ViewState["EMPLOYEE_ID"] != null)
            {
                EmployeeDinnerBean dataBean = new EmployeeDinnerBean();
                EmployeeDinnerDao Dao = new EmployeeDinnerDao();

                dataBean.EmployeeId = string.IsNullOrEmpty(this.txtEmpId.Text.Trim()) ? null : this.txtEmpId.Text;
                if (!string.IsNullOrEmpty(this.txtDate.Text))
                    dataBean.DinnerDate = DateUtils.convertToDate(this.txtDate.Text);
                IList dataList = Dao.ListEmployeeDinners(dataBean);
                this.GridView1.DataSource = dataList;
                this.GridView1.DataBind();
            }

        }
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            e.Row.Cells[0].Text = Convert.ToString(e.Row.RowIndex + 1);


        }
    }
    protected void GridView1_OnRowEditing(object sender, GridViewEditEventArgs e)
    {
        string dinnerId = Convert.ToString((sender as GridView).DataKeys[e.NewEditIndex].Values[0]);
        Context.Items["EMPLOYEE_ID"] = this.ViewState["EMPLOYEE_ID"];
        Context.Items["DINNER_DATE"] = this.ViewState["DINNER_DATE"];
        Context.Items["EMPLOYEE_NAME"] = this.ViewState["EMPLOYEE_NAME"];
        Context.Items["DINNER_ID"] = dinnerId;
        string url = "~/App/Input/EmployeeDinnerUpdForm.aspx";
        ControllerUtils.Transfer(Context, url, true);   
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        EmployeeDinnerBean dataBean = new EmployeeDinnerBean();
        EmployeeDinnerDao Dao = new EmployeeDinnerDao();

        dataBean.EmployeeId = string.IsNullOrEmpty(this.txtEmpId.Text.Trim()) ? null : this.txtEmpId.Text;
        if (!string.IsNullOrEmpty(this.txtDate.Text))
            dataBean.DinnerDate = DateUtils.convertToDate(this.txtDate.Text);
        IList dataList= Dao.ListEmployeeDinners(dataBean);
        this.GridView1.DataSource = dataList;
        this.GridView1.DataBind();

        ViewState["EMPLOYEE_ID"] = this.txtEmpId.Text;
        ViewState["DINNER_DATE"] = this.txtDate.Text;
        ViewState["EMPLOYEE_NAME"] = this.txtEmpName.Text;
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        Context.Items["EMPLOYEE_ID"] = this.ViewState["EMPLOYEE_ID"];
        Context.Items["DINNER_DATE"] = this.ViewState["DINNER_DATE"];
        Context.Items["EMPLOYEE_NAME"] = this.ViewState["EMPLOYEE_NAME"];
        string url = "~/App/Input/EmployeeDinnerUpdForm.aspx";
        ControllerUtils.Transfer(Context, url, true);   
    }
}
